package fresher.utility;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * Date convert utility used in project
 */
public class DateConvertUtility {

    private static SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

    public static long toInteger(String dateString) throws ParseException {
        Date date = formatter.parse(dateString);
        return date.getTime() / 1000;
    }

    public static Date toDate(long timeStamp) {
        return new Date(timeStamp * 1000);
    }

    public static String toString(long timeStamp) {
        return formatter.format(toDate(timeStamp));
    }

    public static Date toDate(String date) {
        try {
            return formatter.parse(date);
        } catch (ParseException ex) {
            Logger.getLogger(DateConvertUtility.class.getName()).log(Level.SEVERE, null, ex);
            return toDate(date);
        }
    }
}
